using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Collections;


/// <summary>
/// Summary description for DALCustomers
/// </summary>
[System.ComponentModel.DataObject]
public class DALCustomers
{
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public static List<Customer> GetCustomers()
    {
        return DAL.GetDataItems<Customer>(SQL.GetCustomers, new string[] { }, new object[] { });
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
    public static List<Customer> GetCustomersByID(int customerID)
    {
        return DAL.GetDataItems<Customer>(SQL.GetCustomersByID, new string[] { "@CustomerID" }, new object[] { customerID });
    }

    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
    public static List<Customer> GetCustomersByFullName(string fullName)
    {
        return DAL.GetDataItems<Customer>(SQL.GetCustomersByFullName, new string[] { "@FullName" }, new object[] { fullName });
    }

    public static int InsertCustomer(string contactNumber, string fullName, string address, string email, string phoneNumber)
    {
        SqlCommand command = DAL.CreateCommand();
        command.CommandText = SQL.InsertCustomer;
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("@ContactNumber", contactNumber);
        command.Parameters.AddWithValue("@FullName", fullName);
        command.Parameters.AddWithValue("@Address", address);
        command.Parameters.AddWithValue("@Email", email);
        command.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
        return DAL.ExecuteNonQuery(command);
    }

    public static int UpdateCustomer(int customerID, string contactNumber, string fullName, string address, string email, string phoneNumber)
    {
        SqlCommand command = DAL.CreateCommand();
        command.CommandText = SQL.UpdateCustomer;
        command.CommandType = CommandType.Text;
        command.Parameters.AddWithValue("@CustomerID", customerID);
        command.Parameters.AddWithValue("@ContactNumber", contactNumber);
        command.Parameters.AddWithValue("@FullName", fullName);
        command.Parameters.AddWithValue("@Address", address);
        command.Parameters.AddWithValue("@Email", email);
        command.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
        return DAL.ExecuteNonQuery(command);
    }

    public static int DeleteCustomers(ArrayList customerIDs)
    {
        SqlCommand command = DAL.CreateCommand();
        command.CommandType = CommandType.Text;

        string s = "";
        foreach (string id in customerIDs)
        {
            s += id + ",";
        }
        s = s.Substring(0, s.LastIndexOf(","));
        command.CommandText = SQL.DeleteCustomers + "(" + s + ")";

        return DAL.ExecuteNonQuery(command);
    }
}
